package aptech.eproject.logictics.dao;

import aptech.eproject.logictics.dao.kien.BookingManagementServiceRemote;
import aptech.eproject.logictics.dao.kien.BranchServiceRemote;
import aptech.eproject.logictics.dao.kien.LoginServiceRemote;
import aptech.eproject.logictics.dao.kien.VehicleServiceRemote;
import aptech.eproject.logictics.dao.thinh.ReportServiceRemote;
import aptech.eproject.logictics.dao.thinh.RouteManageRemote;
import java.util.List;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 *
 * @author Kien Nguyen <solidfoxrock at gmail.com>
 */
public class Util {

    // <editor-fold defaultstate="collapsed" desc="Util Methods of Thinh">
    public static String parseListToString(List lst) {
        String lstOfValues = "";
        for (int i = 0; i < lst.size(); i++) {
            String str = lst.get(i) + "";
            if (i == (lst.size() - 1)) {
                lstOfValues += "" + str + "";
            } else {
                lstOfValues += "" + str + ",";
            }
        }
        return lstOfValues;
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Util Methods of Khoa">
    // </editor-fold>
    
    // <editor-fold defaultstate="collapsed" desc="Util Methods of An">
    // </editor-fold>
    
    // <editor-fold defaultstate="collapsed" desc="Util Methods of Kien">
    public static LoginServiceRemote lookupLoginService() {
        try {
            Context c = new InitialContext();
            return (LoginServiceRemote) c.lookup("stateless/LoginServiceJNDI");
        } catch (NamingException ne) {
            System.err.println("Namming not found ...");
            throw new RuntimeException(ne);
        }
    }

    public static BookingManagementServiceRemote lookupBookingManagementService() {
        try {
            Context c = new InitialContext();
            return (BookingManagementServiceRemote) c.lookup("stateless/BookingManagementServiceJNDI");
        } catch (NamingException ne) {
            System.err.println("Namming not found ...");
            throw new RuntimeException(ne);
        }
    }

    public static VehicleServiceRemote lookupVehicleService() {
        try {
            Context c = new InitialContext();
            return (VehicleServiceRemote) c.lookup("stateless/VehicleServiceJNDI");
        } catch (NamingException ne) {
            System.err.println("Namming not found ...");
            throw new RuntimeException(ne);
        }
    }

    public static BranchServiceRemote lookupBranchService() {
        try {
            Context c = new InitialContext();
            return (BranchServiceRemote) c.lookup("stateless/BranchServiceJNDI");
        } catch (NamingException ne) {
            System.err.println("Namming not found ...");
            throw new RuntimeException(ne);
        }
    }

    public static ReportServiceRemote lookupReportService() {
        try {
            Context c = new InitialContext();
            return (ReportServiceRemote) c.lookup("stateless/ReportServiceJNDI");
        } catch (NamingException ne) {
            System.err.println("Namming not found ...");
            throw new RuntimeException(ne);
        }
    }

    public static RouteManageRemote lookupRouteService() {
        try {
            Context c = new InitialContext();
            return (RouteManageRemote) c.lookup("stateless/ManageRouteJNDI");
        } catch (NamingException ne) {
            System.err.println("Namming not found ...");
            throw new RuntimeException(ne);
        }
    }
    // </editor-fold>
}
